from flask import Blueprint,request,g
from src.Service.Productservice import ProductService


ProductController = Blueprint('ProductController',__name__)
productservice = ProductService()

@ProductController.route("/add",methods=['GET','POST'])
def index():
    props = request.json
    name,price,oldPrice,sellCount,rating,icon,image,typeId = (props.get('name'),
                                                              props.get('price'),
                                                              props.get('oldPrice'),
                                                              props.get('sellCount'),
                                                              props.get('rating'),
                                                              props.get('icon'),
                                                              props.get('image'),
                                                              props.get('typeId'),
                                                              )
    return productservice.insertProduct(name,float(price),float(oldPrice),int(sellCount),int(rating),icon,image,int(typeId))

@ProductController.route("/getProductList")
def getProductList():
    return productservice.getProductList()